import pygame

SIZE = 10
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)

# Celda de automata celular
class Cell(pygame.sprite.Sprite):
    
    def __init__ (self, color=None, size=None, pos=None):
        global N, cells
        # Inicializo Sprite
        pygame.sprite.Sprite.__init__ (self) 
        
        if size == None:
            size = (SIZE,SIZE)
            
        image = pygame.Surface(size)
        image = image.convert()
        
        if color==None:
            # 0 = blanco, 1 = negro
            # 0 = muerto, 1 = vivo
            color = 0
        self.color = color
        self.new_color = color
        
        if color:
            # Lo lleno de negro
            image.fill( BLACK )
        else:
            
            image.fill( WHITE )
            
        self.image = image
        self.rect = image.get_rect()
        
        self.pos = (0,0)
        if pos != None:
            self.pos = pos
        
        self.rect.topleft = pos
        
        
        
    def change_color(self):
        
        if self.color:
            self.image.fill(WHITE)
        else:
            self.image.fill(BLACK)
            
        self.color = self.color ^ 1
        
    
    
    def set_color(self, value):
        
        if value <= 1:
            # Lo lleno de blanco
            self.image.fill( WHITE )
        elif value >= 250:
            self.image.fill( BLACK )
        elif 1 < value < 50 :
            # tope 150
            color = 200 - value
            self.image.fill((color,color,color))
        elif 50 <= value < 100 :
            # tope 150
            color = 180 - value
            self.image.fill((color,color,color))
        elif 100 <= value < 250 :
            # tope 150
            color = 250 - value
            self.image.fill((color,color,color))
        
            
    def update_color(self, value):
        color = self.color + value
        self.image.fill((color,color,color))
